<template>
  <image @click="img_click" :src="img_url" :mode="mode" :class="className" />
</template>

<script>
export default {
  props: {
    url: {
      default: "",
    },
    mode: {
      default: "aspectFill",
    },
    className: {},
  },
  data() {
    return {
      img_url: "",
    };
  },
  watch: {
    url() {
      this.set_url();
    },
  },
  created() {
    this.set_url();
  },
  methods: {
    set_url() {
      const path = uni.getStorageSync("file") || "";
      if (this.url) {
        if (this.url.indexOf("http") > -1) {
          this.img_url = this.url;
        } else {
          this.img_url = path + "/file" + this.url;
        }
      } else {
        this.img_url = "../static/icon_default.png";
      }
    },
    img_click() {
      this.$emit("set_url_my");
    },
  },
};
</script>

<style scoped>
::v-deep .img {
  width: 100%;
  height: 100%;
}
.bg {
  height: 300rpx;
  width: 100%;
  margin-bottom: 20rpx;
  background-size: cover;
  background-repeat: no-repeat;
}
</style>
